package pt.inescid.components.policyengine.heimdall.authorization;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pt.inescid.components.policyengine.heimdall.commons.Log;
import pt.inescid.components.policyengine.heimdall.commons.ProjectInfo;

public class LoginFC extends HttpServlet {

	public void doGet(
					HttpServletRequest request,
					HttpServletResponse response)
			throws IOException, ServletException {

		response.setContentType("text/html");
		response.setDateHeader("Expires", 0);
		response.setHeader("Pragma", "no-cache");

		if (request.getProtocol().equals("HTTP/1.1")) {
			response.setHeader("Cache-Control", "no-cache");
		}

/* ===========================================================
==============================================================
=============                    =============================
=============      control access          =============================
=============                    =============================
==============================================================
=========================================================== */


/* ===========================================================
==============================================================
=============                    =============================
=============      Global variables        ===========
=============                    =============================
==============================================================
=========================================================== */

		String nextURL = null;
		
/* ===========================================================
==============================================================
=============                    =============================
=============      Read Request Parameters        ===========
=============                    =============================
==============================================================
=========================================================== */

/* ===========================================================
==============================================================
=============                    =============================
=============      FINALLY - Redirect    =====================
=============                    =============================
==============================================================
=========================================================== */

		nextURL = "/" + ProjectInfo.getProperty(
				ProjectInfo.APP_NAME_PROPERTY) +
				"/main.jsp?user=1&token=abc";
		
		Log.debug(Log.DEBUG, "Invoking " + nextURL, "LoginFC");
		
		response.encodeURL(nextURL);
		response.sendRedirect(nextURL);

	};


/* ===========================================================
==============================================================
=============                    =============================
=============      doPost       =====================
=============                    =============================
==============================================================
=========================================================== */
	public void doPost(HttpServletRequest request, 
                      HttpServletResponse response)
        throws IOException, ServletException {
       doGet(request, response);
    }
}
